package com.sykj.manage.web;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
 * 
 * @author 高志远
 *2018年9月13日下午5:31:35
 *类描述：菜单配置[sys_role控制类
 */
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sykj.manage.service.SysMenuService;
import com.sykj.manage.model.SysMenu;
import com.sykj.util.ManageBody;
import com.sykj.util.PageUtil;
@Controller
@RequestMapping("/sys")
public class SysMenuController {
	@Autowired
	SysMenuService sysMenuService;
	
	/**
	 * 菜单管理
	 * @param sysMenu
	 * @return
	 */
	@RequestMapping("/findMenus")
	@ResponseBody
	public ManageBody FindMenus(SysMenu sysMenu,Integer offset,Integer pageSize) {
		PageHelper.startPage(offset==null?1:PageUtil.getPageNum(offset, pageSize),pageSize==null?10:pageSize,true);
		List<SysMenu> menus = sysMenuService.findMenus(sysMenu);
		PageInfo<SysMenu> pageInfo = new PageInfo<SysMenu>(menus);
		return ManageBody.getData((int)pageInfo.getTotal(), pageInfo.getList(), "");
	}
	
	/**
	 * 删除菜单
	 * @param menu_id
	 * @return
	 */
	@RequestMapping("/delMenus")
	@ResponseBody
	public Object delMenus(@RequestParam("menu_id")String[] menu_id) {
		int cnt = sysMenuService.delMenus(menu_id);
		return cnt;
	}
	/**
	 * 根据menu_id查询菜单
	 * @param menu_id
	 * @return
	 */
	@RequestMapping("/findMenuById")
	@ResponseBody
	public Object findMenuById(@RequestParam("menu_id")String menu_id) {
		SysMenu menu = sysMenuService.findMenuByID(menu_id);
		return menu;
	}
	
	
	/**
	 * 添加菜单
	 * @param sysMenu
	 * @return
	 */
	@RequestMapping("/addMenu")
	@ResponseBody
	public Object addMenu(SysMenu sysMenu) {
		Date date = new Date();
		sysMenu.setCreate_time(date);
		int addcnt = sysMenuService.addMenu(sysMenu);
		return addcnt;
	}
	
	/**
	 * 菜单管理查询
	 * @param sysMenu
	 * @return
	 */
	@RequestMapping("/findMenusID")
	@ResponseBody
	public Object findMenusID(SysMenu sysMenu) {
		List<SysMenu> menus = sysMenuService.findMenus(sysMenu);
		return menus;
	}
	
	/**
	 * 修改菜单
	 * @param sysMenu
	 * @return
	 */
	@RequestMapping("/updMenu")
	@ResponseBody
	public Object updMenu(SysMenu sysMenu) {
		Date date = new Date();
		sysMenu.setModify_time(date);
		int updcnt = sysMenuService.updMenu(sysMenu);
		return updcnt;
	}

}
